% please textwrap! It helps svn not have conflicts across a multitude of
% lines.
%
% vim:set textwidth=78:


\section{Modeling}
\label{sec:flow}

In this section, we explain our models we use to predict the donation 
probability and donation amounts. In particular, we build a linear regression model 
similar to that in Assignment 1 where we learn the weights of features that
predict the donation amount variable, TARGET\_D, only for those donors that
responded to the 97K mailing or for whom 
TARGET\_B = 1. We build a logistic 
regression model on lines similar to Assignments 2 and 3 to predict the
probability of donation when solicited. For this, we learn a training model with 
features that best predict TARGET\_B for all donors.

We combine these two models to form our final model to predict the expected
donation amount as a result of the solicitation. Since our first model
gives the probability whether a prospective donor will donate, our second
model can use that TARGET\_B = 1 due to Bayes Rule.

We preproces the data for both the SVM and linear regression as follows.

\subsection{Initializing Data}
We start our flow by loading the raw data and manually assign each useful feature a type such
as numeric, real, or binominal. We pick each attribute's type depending on
the transformations we plan to perform to improve their usefulness. 

\subsection{Improving Feature Usefulness}
To begin improving feature's usefulness, we begin by converting compound types
into distinct features. For example, for all of the recency, frequency and
amount fields (e.g. RFA\_3), we split these into three separate features and remove
the original attribute.

Next, we transform missing values into classifiers for identifying our targets.
We accomplish this by replacing the missing values with special values that
represent the meaning of missing values. To illustrate, missing values in the
date a particular gift was returned indicated that the example did not donate
during this period. Thus, replacing missing values with zero and discretizing
by binning into a zero and non-zero bin creates a new attribute indicating
whether a person donated during the period.

After this step, we convert all of our nominal values to binominal values to
maintain their independence. Eventually, we convert all of our
features to numerical values as against the default method that transforms them all into
equal rankings which relates them linearly. By not converting to binominals,
we incorrectly encode the feature's meaning.

Next, we convert all of our features to numerical values so that the SVM and linear regression
operators can build a model using them. We then normalize the data using a z-score
transformation and replace all of the missing features with their average.

This process is also followed for the test data set as well since the test data 
fields should have the same data types when the training models are applied to them.
Apart from the above test data is sorted by the field CONTROL\_N.

\subsection{Constructing the Model}
After preprocessing all of our data, we construct the two training models. 
We build the logistic regression model using a Fast Large Margin operator of Rapidminer 
with a L2 Logistic Regression kernel.
The linear regression model is built using the normal linear regression operator. The final models are
presented in Section \ref{sec:results}.

\subsection{Applying Model to Test Data}
The final models obtained are then applied to the preprocessed test data only once. 
The predictions obtained from logistic regression when applied on test data is shown 
$p(x)$. The predictions from linear regression model is shown as $a(x)$.

The product $p(x).a(x)$ is then calculated for each of the donors in the test dataset.
We apply the definition of optimality as mentioned in \ref{sec:opt} to find the
subset of donors to whom the solicitation should be sent. Thus the final subset consists
of donors for whom $p(x).a(x) \geq 0.68$.

We then compute the profit that the organization could have gained if this subset was
solicited by using the valtgt.txt file which consists of actual donation amounts. We index
by CONTROL\_N into the subset of customers obtained from the previous step and add the donation
amounts for each. The result of this step is explained in the \ref{sec:results}. 

